package com.im.util;

/**
 * @author wangxh
 * @ClassName: CommonPjo
 * @Description: 序列生成公共类
 * @date 2017/5/15 14:47
 */
public class CommonPjo {

	/**
	 * 实例ID生成公用方法
	 * @return
	 */
	public static Long IndexCreate(Long Index) {
		//获取系统当前时间所在的日期
	  
		String currentDt = DateUtil.getNowII().substring(2, 7);
		if(Index==null||!(currentDt.equals(Index.toString().substring(0, String.valueOf(Index).length()>5?5:String.valueOf(Index).length())))){
			//实例表中没有数据，新生成，如果有数据，则看是不是在同一天
			String IndexStr = DateUtil.getNowII().substring(2, 7)+"000001";
			Index =  Long.parseLong(IndexStr);
		}else{
			Index = Index+1;
		}
		return Index;
	}
	
	/**
	 * 默认账号生成
	 * @param custId
	 * @param phonenum
	 * @return
	 */
	public static final String createAcctNum(Long custId,String phonenum) {
		int custIdSize = custId.toString().length();
		String custIdStr = "";
		if(custIdSize>=4){
			custIdStr = custId.toString().substring(custIdSize-3, custIdSize);
		}else{
			custIdStr = custId.toString();
		}
        return Domain.ACCTNUMSINGE +"_"+phonenum.substring(1)+custIdStr;
	}
	
	/**
	 * 邀请码生成
	 */
	public static final String createInviteCode(String InviteCodeIndex) {
		if(StringUtil.isEmpty(InviteCodeIndex)){
			InviteCodeIndex = Domain.DEFAULT_INVITECODE;
		}else{
			Long InviteCodeIndexL = Long.parseLong(InviteCodeIndex)+1;
			InviteCodeIndex =InviteCodeIndexL.toString();
		}
        return InviteCodeIndex;
	}
}
